﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Net;
using System.Net.Sockets;

using P2PLib.Client;
using P2PLib.Common.Command;
using P2PLib.Common.DataModel;

namespace ClientTest
{
    /// <summary>
    /// Window1.xaml 的交互逻辑
    /// </summary>
    public partial class Window1 : Window
    {
        Client client;
        public Window1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            string ip=IPBox.Text;
            int port=int.Parse(PortBox.Text);

            string strHostName = Dns.GetHostName(); //得到本机的主机名
            IPHostEntry ipEntry = Dns.GetHostByName(strHostName); //取得本机IP
            string strAddr = ipEntry.AddressList[0].ToString(); //假设本地主机为单网卡 

            ClientInfo info = new ClientInfo(strAddr, 3456);

            //create instane of client
            client=new Client(new IPEndPoint(IPAddress.Parse(ip),port),info);
            client.ConnectToServer();

            

            //client.SendCommandToServer(new CSConnectCommand(client.Info));
        }

        private void SearchButton_Click(object sender, RoutedEventArgs e)
        {
            string keyword = SearchTextBox.Text;

            if (client != null && client.IsConnected)
            {
                client.SearchFileByName(keyword);
            }
        }
    }
}
